package com.xdl.backstage.base.service.logic;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.xdl.backstage.base.dao.CompanyDao;
import com.xdl.backstage.base.domain.Company;

public class CompanyServiceLogic {

	private static volatile CompanyServiceLogic instance = null;
	@Autowired
	private CompanyDao companyDao;
	
	private Map<String, Company> mapCompany;
	
	public static CompanyServiceLogic getInstance() {
		if (instance == null) {
			synchronized (CompanyServiceLogic.class) {
				if (instance == null) {
					instance = new CompanyServiceLogic();
				}
			}
		}
		return instance;
	}
	
	private CompanyServiceLogic() {
		List<Company> listAll = companyDao.queryDataByParams(null);
		if (listAll != null) {
			mapCompany  = new HashMap<>();
			for (Company company : listAll) {
				mapCompany.put(company.getId(), company);
			}
		}
	}
	
	public Company getData(String companId) {
		if (this.mapCompany.containsKey(companId)) {
			return this.mapCompany.get(companId);
		}
		return null;
	}
	
	
	
}
